- @no_container = true
- page_title "#{@build.name} (##{@build.id})", "Jobs"
= render "projects/pipelines/head"

%div{ class: container_class }
  .build-page
    = render "header"

    - if @build.stuck?
      - unless @build.any_runners_online?
        .bs-callout.bs-callout-warning.js-build-stuck
          %p
            - if no_runners_for_project?(@build.project)
              This job is stuck, because the project doesn't have any runners online assigned to it.
            - elsif @build.tags.any?
              This job is stuck, because you don't have any active runners online with any of these tags assigned to them:
              - @build.tags.each do |tag|
                %span.label.label-primary
                  = tag
            - else
              This job is stuck, because you don't have any active runners that can run this job.

            %br
            Go to
            = link_to namespace_project_runners_path(@build.project.namespace, @build.project) do
              Runners page

    - if @build.starts_environment?
      .prepend-top-default.js-environment-container
        .environment-information
          - if @build.outdated_deployment?
            = ci_icon_for_status('success_with_warnings')
          - else
            = ci_icon_for_status(@build.status)

          - environment = environment_for_build(@build.project, @build)
          - if @build.success? && @build.last_deployment.present?
            - if @build.last_deployment.last?
              This job is the most recent deployment to #{environment_link_for_build(@build.project, @build)}.
            - else
              This job is an out-of-date deployment to #{environment_link_for_build(@build.project, @build)}.
              View the most recent deployment #{deployment_link(environment.last_deployment)}.
          - elsif @build.complete? && !@build.success?
            The deployment of this job to #{environment_link_for_build(@build.project, @build)} did not succeed.
          - else
            This job is creating a deployment to #{environment_link_for_build(@build.project, @build)}
            - if environment.try(:last_deployment)
              and will overwrite the #{deployment_link(environment.last_deployment, text: 'latest deployment')}

    .prepend-top-default.js-build-erased
      - if @build.erased?
        .erased.alert.alert-warning
          - if @build.erased_by_user?
            Job has been erased by #{link_to(@build.erased_by_name, user_path(@build.erased_by))} #{time_ago_with_tooltip(@build.erased_at)}
          - else
            Job has been erased #{time_ago_with_tooltip(@build.erased_at)}

    .prepend-top-default
      .build-trace-container#build-trace
        .top-bar.sticky
          .js-truncated-info.truncated-info.hidden<
            Showing last
            %span.js-truncated-info-size.truncated-info-size><
            KiB of log -
            %a.js-raw-link.raw-link{ href: raw_namespace_project_job_path(@project.namespace, @project, @build) }>< Complete Raw
          .controllers
            - if @build.has_trace?
              = link_to raw_namespace_project_job_path(@project.namespace, @project, @build),
                      title: 'Open raw trace',
                      data: { placement: 'top', container: 'body' },
                      class: 'js-raw-link-controller has-tooltip' do
                = icon('download')

            - if can?(current_user, :update_build, @project) && @build.erasable?
              = link_to erase_namespace_project_job_path(@project.namespace, @project, @build),
                        method: :post,
                        data: { confirm: 'Are you sure you want to erase this build?', placement: 'top', container: 'body' },
                        title: 'Erase Build',
                        class: 'has-tooltip js-erase-link' do
                = icon('trash')

            %button.js-scroll-up.btn-scroll.btn-transparent.btn-blank.has-tooltip{ type: 'button',
                    disabled: true,
                    title: 'Scroll Up',
                    data: { placement: 'top', container: 'body'} }
              = custom_icon('scroll_up')
            %button.js-scroll-down.btn-scroll.btn-transparent.btn-blank.has-tooltip{ type: 'button',
                    disabled: true,
                    title: 'Scroll Down',
                    data: { placement: 'top', container: 'body'} }
              = custom_icon('scroll_down')
        .bash.sticky.js-scroll-container
          %code.js-build-output
          .build-loader-animation.js-build-refresh

  = render "sidebar"

.js-build-options{ data: javascript_build_options }
